﻿/// <reference path="../GeneratedArtifacts/viewModel.js" />

myapp.BrowsePlaces.PlaceIsShared_render = function (element, contentItem) {
    createBooleanSwitch(element, contentItem, 'Shared', 'Private', '', '10em');
};
myapp.BrowsePlaces.created = function (screen) {
    screen.PlaceIsShared = true;
    screen.addChangeListener("PlaceIsShared", function (e) {
        screen.PlaceUserName = (screen.IsShared ? null : result);
    });
    //SignalR notifications
    $(function () {
        /*placeHub = $.connection.placeHub;
        placeHub.client.broadcastMessage = function (message) {
            //if (message.indexOf("address:") !== -1) //filter broadcasting by some creteria...
            {
                screen.placeUpdates = message;
            }
            //placeUpdatesDiv(message);
            //$placeUpdatesDiv.empty();
            //$placeUpdatesDiv.val(message);
            //$(message).appendTo($placeUpdatesDiv);
            //$placeUpdatesDiv.popup("open");
            //screen.showPopup("UpdatePlaces");
            setTimeout(function () {
                //$placeUpdatesDiv.popup("close");
                //screen.closePopup();
                screen.placeUpdates = "";
            }, 5000);

            //$(message + '<a href="#my-header" data-rel="close">Close panel</a>').appendTo($placeUpdatesDiv);
            //$("#placeUpdatesDiv").panel("open", optionsHash);
        };
        movementHub = $.connection.movementHub;
        movementHub.client.broadcastMessage = function (message) {
            //if (message.indexOf("address:") !== -1) //filter broadcasting by some creteria...
            {
                screen.movementUpdates = message;
            }

            //movementUpdatesDiv.val(message);
            //$movementUpdatesDiv.empty();
            //$(message).appendTo($movementUpdatesDiv);
            //screen.showPopup("UpdateMovements");
            //$('#movementUpdatesPopup').popup("open");
            setTimeout(function () {
                screen.movementUpdates = "";
            }, 5000);

            //$(message + '<a href="#my-header" data-rel="close">Close panel</a>').appendTo($movementUpdatesDiv);
            //$("#movementUpdatesDiv").panel("open", optionsHash);
        };
        $.connection.hub.start()
            .done(function () {
            })
            .fail(function () {
                alert("Could not Connect! - ensure EnableCrossDomain = true");
            });
            */
    });

};


/*
var $placeUpdatesDiv;
myapp.Home.placeUpdates_render = function (element, contentItem) {
    $placeUpdatesDiv = $('<div id="placeUpdatesDiv"/>').appendTo($(element));
    //$placeUpdatesDiv = $('<div data-role="content" id="placeUpdatesDiv"><a href="#placeUpdatesPanel" data-role="button" data-inline="true" data-icon="bars">Show Panel</a></div><div data-role="panel" id="placeUpdatesPanel" data-theme="b">panel content</div>').appendTo($(element));

    //placeUpdatesDiv = $('<div data-role="panel" id="placeUpdatesDiv"><a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a></div>').appendTo($(element));
    //placeUpdatesDiv = $('<div data-role="content" id="placeUpdatesDiv"><a href="#placeUpdatesPanel" data-role="button" data-inline="true" data-icon="bars">Show Panel</a></div><div data-role="panel" id="placeUpdatesPanel" data-theme="b"><div class="panel-content"><p>This panel has all the default options...</p><a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a></div>').appendTo($(element));
    //placeUpdatesDiv = $('<div data-role="content" id="placeUpdatesDiv"><a href="#placeUpdatesPanel" data-role="button" data-inline="true" data-icon="bars">Show Panel</a></div><div data-role="panel" id="placeUpdatesPanel" data-theme="b"><div class="panel-content"><p>This panel has all the default options...</p><a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a></div>').appendTo($(element));
};
*/

myapp.BrowsePlaces.ShowFindPlace_execute = function (screen) {
    // Write code here.
    myapp.showFindPlace({
        beforeShown: function (findPlaceScreen) {
            //var newCustomer = new myapp.Customer();
            findPlaceScreen.PlaceId = null;
            findPlaceScreen.CarId = null;
            findPlaceScreen.PlaceIsShared = screen.PlaceIsShared;
            findPlaceScreen.PlaceLocation = screen.PlaceLocation;
        },
        afterClosed: function (findPlaceScreen, navigationAction) {
            // If the user commits the change,
            // show the new Customer in View Screen.
            //if (navigationAction === msls.NavigateBackAction.commit) {
            screen.PlaceId = findPlaceScreen.PlaceId;
                //myapp.showViewCustomer(newCustomer);
            //}
        }
    });
};